package info.xiao.dataStructrue.array;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * @Classname FindMedianSortedArrays  寻找两个正序数组的中位数
 * @Description 链接: https://leetcode.cn/problems/median-of-two-sorted-arrays/
 * @Date 2022/9/26 14:57
 * @Created by 晓龙Oba
 */
public class FindMedianSortedArrays {

    public static void main(String[] args) {
//        int[] A = {1, 2};
//        int[] B = {3, 4};
//        Double result = findMedianSortedArrays(A, B);
//        System.out.println(result);
        String a = "01";
        Integer i = Integer.valueOf(a);
        System.out.println(i);

    }


    /*合并数组*/
    private static Double findMedianSortedArrays(int[] a, int[] b) {
        // 第一步 合并数组
        ArrayList<Integer> list = new ArrayList<>();
        for (Integer element : a) {
            list.add(element);
        }
        for (Integer element : b) {
            list.add(element);
        }
        list.sort(Comparator.naturalOrder());
        if (list.size() % 2 == 0) {
            Double db = (list.get(list.size() / 2) + list.get(list.size() / 2 - 1)) / 2.0;
            return db;
        } else {
            Double db = list.get(list.size() / 2) * 1.0;
            return db;
        }
    }
}
